<template>
	<view class="bgfff">
		<u-navbar title="绑定业务员" title-color="#333333" title-bold></u-navbar>
		<view class="">
			<view class="df aic jcsb p30" v-if="!bindUser.nickName">
				<view class="fs30 fwb c3">
					企业邀请码：
				</view>
				<u-input  @blur="blur" type="number" input-align="right" placeholder="请输入6位数字企业邀请码"
						v-model="userCode" />
			</view>
			<view class=" p30" v-else>
				<view class="c3 fs26 mb30">
					当前绑定的业务员
				</view>
				<view class="bind-box-user df aic jcsb">
					<view class="">
						<view class="">
							<text class="fwb fs28 c3 mr20">{{bindUser.nickName||''}}</text><text class="fs24 c3">业务经理</text>
						</view>
						<view class="mt15 fs24 c3">
							{{bindUser.phonenumber||''}}
						</view>
					</view>
					<view class="" @click="cellPhone">
						<image src="../../../static/my/dianhua-5.png" style="width: 50rpx;height: 50rpx;"></image>
					</view>
				</view>
				<!-- <view class="fs30 fwb c3">
					已绑定：
				</view>
				<view class="">
					{{bindUser.nickName}}
				</view> -->
			</view>
			<view class=" p30" v-if="!bindUser.nickName">
				<u-button  :loading="loading" style="width: 702rpx;" type="success" shape="circle" :custom-style="customStyle"
					@click.stop="userMemberBind">
					{{userName ?`确认绑定（${userName}）`:'绑定' }}
					</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {userMemberBind,getAntUserInfo,getAntUser } from '@/api/common.js'
	export default {
		data() {
			return {
				customStyle: {
					background: 'linear-gradient(90deg, #48A147 0%, #8AE38A 100%)',
					borderColor: '#33B775',
				},
				userCode:'',
				userName:'',
				bindUser:{nickName:''},
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			getInfo(){
				getAntUser().then(res =>{
					if(res.code==200){
						this.bindUser = res.data
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							mask:true
						})
					}
				})
			},
			// 反查业务员
			blur(e){
				getAntUserInfo({userCode:e}).then(res =>{
					if(res.code==200){
						this.userName = res.data.nickName
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							mask:true
						})
					}
				})
			},
			userMemberBind(){
				if(!this.userCode){
					this.$u.toast('请输入企业邀请码')
					return
				}
				if(this.userCode.length!==6){
					this.$u.toast('请输入6位数字的企业邀请码')
					return
				}
				this.loading = true
				userMemberBind({userCode:this.userCode}).then(res =>{
					if(res.code==200){
						this.$u.toast('绑定成功')
						setTimeout(() =>{
							uni.navigateBack()
						},800)
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							mask:true
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">

</style>